﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Santa_sAdventure.Model.Enums;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace Santa_sAdventure.Model
{
    class MovingEnemy : Enemy
    {
        // Enemy specific animation
        private Animation m_runAnimation;
        private Animation m_die;
        private AnimationPlayer m_animationPlayer;
        private SpriteEffects flip = SpriteEffects.None;
        // Content
        private ContentManager m_content;        

        internal MovingEnemy(ContentManager a_content)
        {
            m_content = a_content;
            Velocity = new Vector2(-1, 0);

            // Set animations
            m_runAnimation = new Animation(a_content.Load<Texture2D>("Images/Enemy/Moving/Enemy-Run"), 1, true, 10);
            m_die = new Animation(a_content.Load<Texture2D>("Images/Enemy/Enemy-Die"), 1, false, 11);
            m_animationPlayer = new AnimationPlayer(m_runAnimation);
        }

        // Return spriteeffects
        internal override SpriteEffects GetSpriteEffect()
        {
            // Flip the sprite to face the way we are moving.
            if (Velocity.X > 0)
                flip = SpriteEffects.FlipHorizontally;
            else if (Velocity.X < 0)
                flip = SpriteEffects.None;

            return flip;
        }

        // Move enemy
        internal override void Update(float a_totalSeconds)
        {
            Position = Position + Velocity * a_totalSeconds;
        }

        // Return animationplayer
        internal override AnimationPlayer GetAnimationPlayer()
        {
            return m_animationPlayer;
        }

        // Kill enemy
        internal override void KillEnemy()
        {
            m_isDead = true;
            m_animationPlayer.PlayAnimation(m_die);
        }
    }
}
